package com.jdiv.samples.plat;

import com.jdiv.JProcess;

public class Player extends JProcess {

private int vel=8;

private int idle=1;

private int run=22;

private int animationSpeedLimit=2;

private int animationSpeed=animationSpeedLimit;

private int vSalto=20;

private int grav=2;

private int saltando=vSalto;

private int last_y=0;

private boolean isSaltando=false;

	public Player(){
		file=Main.fpg_player;
		graph=1;
		x=900;
		y=630;
	//	alpha=50;
	}
	public void begin(){}
	public void loop(){
		 
		if (key(_LEFT)){ 
		    x-=vel;  
		    flags=0;
	        if(run==32) run=22; else if (animationSpeed==animationSpeedLimit){ run++; animationSpeed=0; }
	        graph=run;
	        animationSpeed++;
	
		}else if (key(_RIGHT)){ 
		    x+=vel;  
		    flags=1;
	        if(run==32) run=22; else if (animationSpeed==animationSpeedLimit){ run++; animationSpeed=0; }
	        graph=run;
	        animationSpeed++;
	
		}else{
		//	graph=idle;
			run=22;
			animationSpeed=animationSpeedLimit;
				
		}
		
		if(key(_SPACE)){
			
			  if (!isSaltando){
				  last_y=y;
				  isSaltando=true;
			  }
		}
	  
		if (isSaltando){
			  saltando-=grav;
	     	  y=y-saltando;
	     	  	if (y==last_y){ isSaltando=false; saltando=vSalto;}
	  
		}
		
	}
	
	
}
